<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="module" src="TestModule.js"></script>
</head>
<body>
    
</body>
<script >
  
      //async函数内部抛出错误 会导致返回的Promise对象变为reject状态
   //抛出的错误对象会被catch方法回调函数接收到
   async function ff(){
        return await Promise.resolve("成功")
        await Promise.reject('出错了呜呜呜')
        console.log("---------")
        await Promise.reject("又出错了呜呜呜").catch(e=>console.log(e))
        return await Promise.resolve("成功")
    }

   ff().then( v => console.log("haha " + v))
   .catch(e => console.log(e))

   async function main(){
     try{
       await Promise.reject("1")
       await Promise.resolve("2").then((value)=>{
         console.log(value)
       })
     }catch(err){
       console.log(err)
     }
   }
   main()

  var p1 = function (){
    return  new Promise(function(resolve,reject){
      resolve("成功")
    })

  }
  var p2 = function(){
    return  new Promise(function(resolve,reject){
      resolve("成功了哦")
    })
  }

    Promise.all([p1(),p2()]).then(v => console.log( v))
   .catch(err => console.log(err))
   
   async function a(){
    let[foo,bar] = await Promise.all([p1(),p2()])
    console.log(foo)
    console.log(bar)
   }
   a()

   
  

</script>
</html>